<?php

/**
* Model:  "Events_model"
*
* This model allows CodeIgniter to interact with the database - more
* specifically, the "events" table in the database.  This model allows
* the application to gather a list of all event records, remove an
* event (or "cancel" it), and add an event (or "schedule" it).
*
* Functions:  list_events, cancel_event, schedule_event
*
* @author     Brandon A Johnson
* @copyright  LIS4368-01: "Web Development with PHP," Spring 2010
* @version    1.0
* @date       April 24, 2010
*
*/

class Events_model extends Model {

	/**
	* Events_model() - constructor
	*
	* allows this file to act as a valid CodeIgniter model
	*/
    function Events_model()
    {
        parent::Model();
		
		// loads the database library for all methods within this model
		$this->load->database();
    }
	
	/**
	* list_events()
	*
	* runs a query that extracts all records currently in the database
	*
	* values passed: none
	*/
	function list_events()
	{
		$query = $this->db->get('events');

		return $query->result();
	}
	
	/**
	* cancel-event()
	*
	* runs a query that deletes the selected record from the database
	*
	* values passed: $selection - event selected from the drop-down list
	*/
	function cancel_event($selection)
	{
		$this->db->query('DELETE FROM events WHERE Name="' . $selection . '";');
	}
	
	/**
	* schedule_event()
	*
	* runs a query that enters a new record into the database
	*
	* values passed: $name - the name of the event
	*                $sponsor - the event's sponsor
	*                $location - the location of the event
	*                $date - year, month, and day the event will be held
	*                $time - the time of the event
	*                $description - a brief event description
	*/
	function schedule_event($name, $sponsor, $location, $date, $time, $description)
	{
		$this->db->query('INSERT INTO events (Name, Sponsor, Location, Date, Time, Description) VALUES ("' . $name . '", "' . $sponsor . '", "' . $location . '", "' . $date . '", "' . $time . '", "' . $description . '");');
	}
}

/* EOF */